package com.imedway.ihe.config;

import java.nio.charset.StandardCharsets;

import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.util.UrlPathHelper;

import com.imedway.ihe.dtz.xds.cons.ConstProperties;
 
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
 
//    @Value("${accessFile.resourceHandler}")
//    private String resourceHandler; 
 
//    @Value("${accessFile.accessFilePath}")
//    private String accessFilePath;
	@Autowired
	private ConstProperties constProperties;
    /**
     * 配置静态资源映射
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 匹配到resourceHandler,将URL映射至accessFilePath（即本地文件夹）
         registry.addResourceHandler("/XDS/**").addResourceLocations("file:"+constProperties.getFileRootPath());
//         registry.addResourceHandler("/XDS/**").addResourceLocations("classpath:/XDS/Repository/");

//        registry.addResourceHandler(resourceHandler).addResourceLocations("file:///" + accessFilePath);
    }
    
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        UrlPathHelper urlPathHelper=new UrlPathHelper();
        urlPathHelper.setUrlDecode(false);
        urlPathHelper.setDefaultEncoding(StandardCharsets.UTF_8.name());
        configurer.setUrlPathHelper(urlPathHelper);
    }

}
 

